Skip to content

Enable WAM Broker support for Entra ID Auth modes#4288

Draft
cheenamalhotra wants to merge 1 commit into
mainfrom
dev/cheena/entra-wam-broker
Draft

Enable WAM Broker support for Entra ID Auth modes#4288
cheenamalhotra wants to merge 1 commit into
mainfrom
dev/cheena/entra-wam-broker

Conversation

@cheenamalhotra
Copy link
Copy Markdown
Member

@cheenamalhotra cheenamalhotra commented May 14, 2026

Enables WAM broker support for below Entra ID auth modes:

  • Integrated
  • Password (deprecated)
  • Interactive
  • Device Code Flow

Copilot AI review requested due to automatic review settings May 14, 2026 02:31
@github-project-automation github-project-automation Bot moved this to To triage in SqlClient Board May 14, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds WAM broker support to the Azure extension authentication provider for Entra ID public-client authentication flows on Windows.

Changes:

  • Adds Microsoft.Identity.Client.Broker dependency and broker configuration during PCA creation.
  • Adds parent-window callback API and Windows interop helpers for WAM prompt parenting.
  • Adds basic tests and a draft feature spec for WAM broker support.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
Directory.Packages.props Adds centralized MSAL broker package version.
src/Microsoft.Data.SqlClient.Extensions/Azure/src/Azure.csproj References the broker package from the Azure extension.
src/Microsoft.Data.SqlClient.Extensions/Azure/src/ActiveDirectoryAuthenticationProvider.cs Makes the provider partial, adds parent-window callback API, and configures WAM broker on Windows.
src/Microsoft.Data.SqlClient.Extensions/Azure/src/ActiveDirectoryAuthenticationProvider.Windows.cs Adds Windows-specific parent-window discovery for broker UI.
src/Microsoft.Data.SqlClient.Extensions/Azure/src/Interop/Interop.GetAncestor.cs Adds user32.GetAncestor interop helper.
src/Microsoft.Data.SqlClient.Extensions/Azure/src/Interop/Interop.GetConsoleWindow.cs Adds kernel32.GetConsoleWindow interop helper.
src/Microsoft.Data.SqlClient.Extensions/Azure/test/WamBrokerTests.cs Adds basic tests for the new parent-window setter.
specs/002-wam-broker/spec.md Adds the draft WAM broker feature specification.
Comments suppressed due to low confidence (5)

src/Microsoft.Data.SqlClient.Extensions/Azure/src/ActiveDirectoryAuthenticationProvider.cs:766

  • The parent-window delegate is captured on the cached PublicClientApplication, but the static PCA cache key does not include the new SetParentActivityOrWindow callback. A later provider instance with the same authority/client/redirect can reuse an app built with an earlier provider's delegate, causing WAM prompts to be parented to the wrong window (or to ignore the later callback). Include the callback identity in the cache key or avoid capturing provider instance state in the cached app.
                builder.WithParentActivityOrWindow(GetBrokerParentWindow);
            }
            #else
            builder.WithParentActivityOrWindow(GetBrokerParentWindow);

src/Microsoft.Data.SqlClient.Extensions/Azure/src/ActiveDirectoryAuthenticationProvider.cs:752

  • The tests added for this feature only exercise the setter and do not verify that Windows PCA construction actually enables the broker or wires the parent-window callback. Please add unit coverage around CreateClientAppInstance (or an observable wrapper) so regressions in the WAM configuration are caught without relying solely on manual integration testing.
        if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
        {
            builder.WithBroker(new BrokerOptions(BrokerOptions.OperatingSystems.Windows));

specs/002-wam-broker/spec.md:70

  • This API description says Func can return IWin32Window, but the implementation only accepts IntPtr from this callback and silently ignores any other object type before falling back to console detection. Please either document only the supported return type or handle IWin32Window here as described.
        // Cross-platform API to set the parent window/activity for WAM dialog
        // On Windows: accepts IntPtr (window handle) or IWin32Window via Func<object>
        // On Unix: no-op (WAM not available)
        public void SetParentActivityOrWindow(Func<object> parentActivityOrWindowFunc);
    

    specs/002-wam-broker/spec.md:131

    • This rollout note is inaccurate: SetIWin32WindowFunc is not changed to delegate to SetParentActivityOrWindow; it still stores a separate _iWin32WindowFunc and the new callback is independent. Please update the spec or implementation so consumers and maintainers do not rely on a delegation behavior that is not present.
    - WAM broker is **always enabled** on Windows when using PCA flows
    - No opt-in connection string keyword needed (aligns with MSAL PCA compliance requirements)
    - Existing `SetIWin32WindowFunc` remains as a backward-compatible API on .NET Framework, delegating to `SetParentActivityOrWindow`
    

    src/Microsoft.Data.SqlClient.Extensions/Azure/src/ActiveDirectoryAuthenticationProvider.cs:749

    • This comment overstates the behavior: the code still uses AcquireTokenByIntegratedWindowsAuth, AcquireTokenByUsernamePassword, and AcquireTokenWithDeviceCode for those modes, so broker configuration does not make every supported authentication mode a WAM flow. Please narrow the comment to the modes MSAL will actually broker or update the acquisition paths accordingly.
            // Enable WAM broker on Windows for all supported authentication modes.
            // The broker provides enhanced security by enabling device-based Conditional Access
            // policies through the Windows Account Manager (WAM).
    


/// <summary>
/// Sets a function to return the parent activity or window handle to be used for
/// WAM (Web Account Manager) broker authentication prompts.
Comment on lines +750 to +752
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
builder.WithBroker(new BrokerOptions(BrokerOptions.OperatingSystems.Windows));
Comment on lines +48 to +49
| `ActiveDirectoryDeviceCodeFlow` | Uses WAM for device code flow on Windows |
| `ActiveDirectoryPassword` | Uses WAM for username/password flow on Windows |
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: To triage

Development

Successfully merging this pull request may close these issues.

2 participants